﻿@page
@model Emprise.Web.Pages.User.RegModel
@{
    ViewData["Title"] = "注册";
}
@{
    Layout = "_Layout";
}

<div class="big_bg" id="app">
    <div class="nav">
        <h2 class="nav-title">注册</h2>
        <a href="@(Url.Page("/User/Login"))" class="nav-back"><span><<返回</span></a>
    </div>

    <div class="main">
        <div>
            <div class="login-nonreg">
                <div class="fn-mt-login fn-mlr">
                    <div>
                        <p>注册邮箱无法修改，忘记密码时可通过邮件找回。</p>
                    </div>
                </div>

                <form>

                    <div class="form-text-login">
                        <label>邮箱：</label>
                        <input type="text" class="form-text" v-model="email" autocomplete="new-password" />
                        <a href="javascript:;" class="form-text-clear" v-show="email" v-on:click="email=''"><i class="icon icon-clear"></i></a>
                    </div>

                    @*
                    <div class="form-text-login">
                        <label>验证码：</label>
                        <input type="text" class="form-text" v-model="code" />
                        <a href="javascript:;" class="form-text-clear"><i class="icon icon-clear"></i></a>
                    </div>
                    *@

                    <div class="form-text-login">
                        <label>密码：</label>
                        <input type="password" class="form-text" v-model="password" autocomplete="new-password" />
                        <a href="javascript:;" class="form-text-clear" v-show="password" v-on:click="password=''"><i class="icon icon-clear"></i></a>
                    </div>

                    <div class="form-text-login">
                        <label>重复：</label>
                        <input type="password" class="form-text" v-model="password2" autocomplete="new-password" />
                        <a href="javascript:;" class="form-text-clear" v-show="password2" v-on:click="password2=''"><i class="icon icon-clear"></i></a>
                    </div>
                </form>

            </div>
            <div class="fn-mt-login fn-mlr">
                <a class="btn btn-bar-tawny" href="javascript:;" v-on:click="reg"> 确 定 </a>
            </div>
            <div class="fn-mt-login fn-mlr" style="text-align:right;">
                <a style="font-size:12px;" href="@(Url.Page("/User/Login"))">已有账号，直接登录</a>
            </div>
            <div class="fn-mt fn-mlr"><span class="tip01 tips">{{tips}}</span></div>
        </div>

    </div>



    <div class="loading" v-show="loading">
        <img src="/images/loading.gif">
    </div>
</div>
@await Html.PartialAsync("_Footer", Model.SiteConfig)

@section Scripts {
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                email: "@(Model.Email)",
                password: "",
                password2: "",
                code:"@(Model.Code)",
                tips: "",
                loading: 0
            },
            methods: {
                reg: function () {
                    var that = this;
                    that.tips = "";

                    if (!that.email || !that.password || !that.password2) {
                        that.tips = "请输入邮箱和密码";
                        return false;
                    }

                    if (that.password!=that.password2) {
                        that.tips = "两次密码不一致";
                        return false;
                    }

                    that.loading = 1;

                    axios.post("", {
                        email: that.email,
                        password: that.password,
                        code:that.code
                    }, {
                        headers: {
                            RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value
                        }
                    })
                    .then(function (response) {
                        var result = response.data;
                        if (result.status) {
                            location.href = "@(Url.Page("/User/Index"))";
                        } else {
                            var error = result.errorMessage || "登录失败";
                            if (result.data) {
                                error += "<br>" + result.data;
                            }
                            that.tips = error;
                        }
                        that.loading = 0;
                    })
                    .catch(function (error) {
                        console.log(error);
                        that.loading = 0;
                    });
                }
            }
        });

    </script>
}

